package com.atguigu.gmall.user.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.user.service.UserInfoService;
import com.atguigu.gmall.user.vo.UserLoginSuccessVo;
import com.atguigu.gmall.user.vo.UserLoginVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author:ahang
 * @create:2022-10-18 11:07
 * @Description:
 */
@RestController
@RequestMapping("/api/user")
public class UserLoginController {

    @Autowired
    UserInfoService userInfoService;

    /**
     * 登录
     * @param userLoginVo
     * @return
     */
    @PostMapping("/passport/login")
    public Result login(@RequestBody UserLoginVo userLoginVo){

        UserLoginSuccessVo successVo = userInfoService.login(userLoginVo);
        return Result.ok(successVo);
    }

    /**
     * 退出
     * @return
     */
    @GetMapping("passport/logout")
    public Result logout(@RequestHeader("token") String token){
        //前端页面会自动删除token,后端只需要删除redis中的数据即可
        userInfoService.logout(token);
        return Result.ok();
    }
}
